<template>
    <div class="padd20">
        <!-- <vue2-org-tree :data = "dataObj" :type = "type" class="txtAlignC" :horizontal = "screenWidth >= 1366 ? false : true"> -->
        <vue2-org-tree :data = "dataObj" :type = "type" class="txtAlignC" horizontal = true>

        </vue2-org-tree>
    </div>
</template>

<script>

import http from '@/assets/js/http'
import _g from '@/assets/js/global'

export default {
    watch: {
          screenWidth (val) {
              this.screenWidth = val
          }
      },
    data(){
        return {
            screenWidth: document.body.clientWidth,
            type:{
                label: 'label',
                expand: 'expand',
                children: 'children',
                // usersCount: 'users_count',
            },
            dataObj:{
                // label : '浙江天创信测通信科技有限公司',
                // peopleCount : undefined,
                // children:[]
            }
        }
    },
    created() {
        this.queryInfiniteLevelStructure()
    },
    mounted () {
        const that = this
        window.onresize = () => {
            return (() => {
                window.screenWidth = document.body.clientWidth
                that.screenWidth = window.screenWidth
            })()
        }
    },
    methods: {
        /* 查询所有组织架构列表 */
        getAllStructure(){
            const that = this

            _g.showLoading('加载中');
            that.apiPost("admin/organization/getAllStructure").then(res => {
                    _g.showLoading().close()
                    if(typeof res === 'string'){
                        res = JSON.parse(res)
                    }
                    if (res.code != 200) {
                        that.handleError(res)
                    } else if(res.data.isSuccess === 0){
                        that.dataObj['children'] = res.data.structureList
                    }else if(res.data.isSuccess === 1){
                        _g.toastMsg("error", res.message)
                        that.$router.push('/admin/structures/list')
                    }
            })
        },
        /* 查询无限级组织架构 */
        queryInfiniteLevelStructure(){
            const that = this

            _g.showLoading('加载中');
            that.apiPost("admin/infiniteLevelStructure/queryInfiniteLevelStructure").then(res => {
                    _g.showLoading().close()
                    if(typeof res === 'string'){
                        res = JSON.parse(res)
                    }
                    if (res.code != 200) {
                        that.handleError(res)
                    } else if(res.data.isSuccess === 0){
                        that.dataObj = (res.data.result)[0]
                    }else if(res.data.isSuccess === 1){
                        _g.toastMsg("error", res.message)
                        that.$router.push('/admin/structures/list')
                    }
            })
        },
        // /* 查询所有组织架构列表 */
        // getAllStructure(){
        //     const that = this

        //     _g.showLoading('加载中');
        //     that.apiPost("admin/organization/getAllStructure").then(res => {
        //             _g.showLoading().close()
        //             if(typeof res === 'string'){
        //                 res = JSON.parse(res)
        //             }
        //             if (res.code != 200) {
        //                 that.handleError(res)
        //             } else if(res.data.isSuccess === 0){
        //                 that.dataObj['children'] = res.data.structureList
        //             }else if(res.data.isSuccess === 1){
        //                 _g.toastMsg("error", res.message)
        //                 that.$router.push('/admin/structures/list')
        //             }
        //     })
        // },
    },
    mixins: [http]
}
</script>

